/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hibernate.Dao;

import hibernate.util.HibernateUtil;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import htmlunit.mode.*;
/**
 *
 * @author TiTa
 */
public class crawlerDao {
   

 private final SessionFactory sf= HibernateUtil.getSessionFactory();
 //  private final Session ss=HibernateUtil.getSessionFactory().getCurrentSession();
    public List tim_tat_ca()
    {
        try {
          sf.getCurrentSession().beginTransaction();//sai cho nay
       return   sf.getCurrentSession().createCriteria(Link.class).list();
           //  ss.beginTransaction();
         //   return ss.createCriteria(Link.class).list();
       //     Session ss=HibernateUtil.getSessionFactory().getCurrentSession();
       // Object link = ss.load(Link.class,1);
       
        } catch (Exception e) {
           return null;
        }
    
    }
    public List<Link> danhsach_tatca_linl()
    { 
        try {
           sf.getCurrentSession().beginTransaction();
          return sf.getCurrentSession().createCriteria(Link.class).list();
           
      
        } catch (Exception e) {
             return null;
        }
            
   
    }
    public List<Hinh> danhsach_tatca_hinh()
    { 
        try {
           sf.getCurrentSession().beginTransaction();
          return sf.getCurrentSession().createCriteria(Hinh.class).list();
           
      
        } catch (Exception e) {
             return null;
        }
            
   
    }
    public List<ThongTin> danhsach_tatca_thongtin()
    { 
        try {
           sf.getCurrentSession().beginTransaction();
          return sf.getCurrentSession().createCriteria(ThongTin.class).list();
           
      
        } catch (Exception e) {
             return null;
        }
            
   
    }
    public List<ThamSo> thamso()
    { 
        try {
           sf.getCurrentSession().beginTransaction();
          return sf.getCurrentSession().createCriteria(ThamSo.class).list();
           
      
        } catch (Exception e) {
             return null;
        }
            
   
    }
    public boolean capnhat(Link l){
        try {
             sf.getCurrentSession().beginTransaction();
             sf.getCurrentSession().save(l);
             sf.getCurrentSession().getTransaction().commit();
             return true;
        } catch (Exception e) {
             sf.getCurrentSession().getTransaction().rollback();
             return false;
        }
    
    } 
      public boolean capnhat(Hinh l){
        try {
             sf.getCurrentSession().beginTransaction();
             sf.getCurrentSession().save(l);
             sf.getCurrentSession().getTransaction().commit();
             return true;
        } catch (Exception e) {
             sf.getCurrentSession().getTransaction().rollback();
             return false;
        }
    
    } 
       public boolean capnhat(ThongTin tt){
        try {
             sf.getCurrentSession().beginTransaction();
             sf.getCurrentSession().save(tt);
             sf.getCurrentSession().getTransaction().commit();
             return true;
        } catch (Exception e) {
             sf.getCurrentSession().getTransaction().rollback();
             return false;
        }
    
    } 
     public boolean xoa(Link l){
         try {
             sf.getCurrentSession().beginTransaction();
             sf.getCurrentSession().delete(l);
             sf.getCurrentSession().getTransaction().commit();
             return true;
         } catch (Exception e) {
             sf.getCurrentSession().getTransaction().rollback();
             return false;
         }
     
     }

public Link tim_them_vao_tblink(String link){
    try {
        sf.getCurrentSession().beginTransaction();
        return (Link) sf.getCurrentSession().get(Link.class,link);
    } catch (Exception e) {
        return null;
    }
}
}
